package com.czl.module_work.fragment

import androidx.lifecycle.Observer
import com.alibaba.android.arouter.facade.annotation.Route
import com.czl.base.base.BaseFragment
import com.czl.base.config.AppConstants
import com.czl.module_work.BR
import com.czl.module_work.R
import com.czl.module_work.adapter.OrderDetailPhotoAdapter
import com.czl.module_work.databinding.WorkFragmentAppointmentDetailBinding
import com.czl.module_work.view.ApplyAuditPop
import com.czl.module_work.view.SharePop
import com.czl.module_work.viewModel.AppointmentDetailViewModel
import com.czl.module_work.viewModel.AppointmentRecordViewModel
import com.lxj.xpopup.XPopup

@Route(path = AppConstants.Router.Work.F_WORK_APPOINTMENT_DETAIL)
class AppointmentDetailFragment :
    BaseFragment<WorkFragmentAppointmentDetailBinding, AppointmentDetailViewModel>() {

    var applyId = ""
    var status = "1"

    override fun useBaseLayout(): Boolean = false;

    override fun initContentView(): Int = R.layout.work_fragment_appointment_detail

    override fun initVariableId(): Int = BR.viewModel

    override fun initData() {
        if (status == "2") {
            viewModel.tvTitle.set("邀约详情")
        } else {
            viewModel.tvTitle.set("预约详情")
        }
        viewModel.getApplyDetail(applyId)
    }

    override fun initParam() {
        status = arguments?.getString(
            AppConstants.BundleKey.WORK_ORDER_STATUS,
        ) ?: ""

        applyId = arguments?.getString(AppConstants.BundleKey.WORK_APPOINTMENT_DETAIL_ID) ?: ""

    }

    override fun initViewObservable() {
        viewModel.uc.showAuditEvent.observe(this, Observer {
            val applyAudioPop = ApplyAuditPop(
                if (it == "2") {
                    "审核通过"
                } else {
                    "审核驳回"
                },requireContext()
            )

            applyAudioPop.setFilterResultListener { content->
                viewModel.applyAudit(content, it)
            }
            XPopup.Builder(context)
                .asCustom(applyAudioPop)
                .show()
        })
    }
}